<?php
	class HouseAction extends BaseAction{
		public function xiezilouadd(){
			if(!$this->isPost()){
				//区域
				$result = M("area")->select();
				$this->assign("area",$result);
				//地铁站
				$ditie  = M("subway")->select();
				$this->assign("ditie",$ditie);
				//租赁方式
				$rent = M("rent")->select();
				$this->assign("rent",$rent);
				//房源类型
				$type = M("type")->select();
				$this->assign("type",$type);
				//商圈
				$district = M("district")->select();
				$this->assign("district",$district);
				//经纪人
				$broker = M("vip")->where("v_type =1 ")->select();
				$this->assign("broker",$broker);
				$this->display();
			}else{
				//获得图片
				$pic = $_FILES['x_img'];
				//获得图的临时路径
				$tmpname = $pic['tmp_name'];
				//获得图片类型
				$type = $pic['type'];
				$type = explode('/',$type);
				$type_1 = $type[0];
				//重新给图片起名
				$picture='xiezilou_'.time().rand(1000,9999).".".$type[1];
				//上传图片时 的报错
				$error=$pic['error'];
				//图片上传的路径
				$newname=ROOT_DIR.DS.'Public/Upload/'.$picture;
				if(is_uploaded_file($tmpname) && $type_1 == 'image' && $error == '0'){
					move_uploaded_file($tmpname,$newname);
				}
				
				
				//楼盘名字
				$data['x_name']=$_POST['x_name'];
				//楼盘图片
				$data['x_img'] = $picture;
				//楼盘位置
				$data['x_location']=$_POST['location'];
				//所 属  区
				$data['x_quyu']=$_POST['x_quyu'];
				//所属商圈
				$data['x_district']=$_POST['x_district'];
				//所属地铁线
				$data['x_subway']=$_POST['x_subway'];
				//所属地铁站
				$data['x_subway_station']=$_POST['x_subway_station'];
				//租赁方式
				$data['x_zulin']=$_POST['x_zulin'];
				//房源类型
				$data['x_type']=$_POST['x_type'];
				//房源位置
				$data['x_location']=$_POST['x_location'];
				//开发商
				$data['x_developers']=$_POST['x_developers'];
				//单价
				$data['x_sell']=$_POST['x_sell'];
				//总价
				$data['x_zongjia']=$_POST['x_zongjia'];
				//日租金
				$data['x_d_rent']=$_POST['x_d_rent'];
				//月租金
				$data['x_m_rent']=$_POST['x_m_rent'];
				//建筑面积
				$data['x_build_area']=$_POST['x_build_area'];
				//使用面积
				$data['x_use_area']=$_POST['x_use_area'];
				//详细标题
				$data['x_title']=$_POST['x_title'];
				//所在楼层
				$data['x_floor']=$_POST['x_floor'];
				//装修状况
				$data['x_decoration']=$_POST['x_decoration'];
				//装修
				$data['x_property'] = $_POST['x_porperty'];
				//楼盘等级
				$data['x_rating']=$_POST['x_rating'];
				//支付方式
				$data['x_pay_type']=$_POST['x_pay_type'];
				//配套设施
				$data['x_supproting']=$_POST['x_supproting'];
				//房源描述
				$data['x_description_info']=$_POST['x_description_info'];
				//图片描述
				$data['x_description_img']=$_POST['x_description_img'];
				//地图交通
				$data['x_description_map']=$_POST['x_description_map'];
				//楼盘简介
				$data['x_summary_info']=$_POST['x_summary_info'];
				//周边设施
				$data['x_nearby']=$_POST['x_nearby'];
				//所属经纪人
				$data['x_broker'] = $_POST['brokers'];
				//是否为精品房源
				$data['is_jingping'] = $_POST['radios'];
				//时间
				$data['times'] = date("Y-m-d H:i:s",time());
				
				$result = M("xiezilou")->data($data)->add();
				if($result){
					$this->assign("jumpUrl","__URL__/xiezilouadd");
					$this->assign("waitSecond",3);
					$this->success("写字楼添加成功！！！");
				}else{	
					$this->assign("jumpUrl","__URL__/xiezilouadd");
					$this->assign("waitSecond",3);
					$this->error("添加失败！！！");
				}


				//$data['']=$_POST[''];
			}
		}

		public function lists(){
			if(!$this->isPost()){
				$xiezilou = M("xiezilou")->select();
				$this->assign("result",$xiezilou);
				$this->display();
			}else{
				if($_POST['fun']=="del"){
					$x_id = $_POST['x_id'];
					$result = M("xiezilou")->where("x_id=$x_id")->delete();
					if($result){
						echo "1"; 
					}else{
						echo "0";
					}
				}
				if($_POST['fun']=='updates'){
					$x_id = $_POST['x_id'];
					$result = M("xiezilou")->where("x_id=$x_id")->select();

					$this->assign("result",$result);	
				
					//区域
					$result = M("area")->select();
					$this->assign("area",$result);
					//地铁站
					$ditie  = M("subway")->select();
					$this->assign("ditie",$ditie);
					//租赁方式
					$rent = M("rent")->select();
					$this->assign("rent",$rent);
					//房源类型
					$type = M("type")->select();
					$this->assign("type",$type);
					//商圈
					$district = M("district")->select();
					$this->assign("district",$district);
					$this->display("updates");
				}
				if($_POST['fun']=='u'){
					$x_id = $_POST['x_id'];
					//获得图片
					$pic = $_FILES['x_img'];
					//获得图的临时路径
					$tmpname = $pic['tmp_name'];
					//获得图片类型
					$type = $pic['type'];
					$type = explode('/',$type);
					$type_1 = $type[0];
					//重新给图片起名
					$picture='xiezilou_'.time().rand(1000,9999).".".$type[1];
					//上传图片时 的报错
					$error=$pic['error'];
					//图片上传的路径
					$newname=ROOT_DIR.DS.'Public/Upload/'.$picture;
					if(is_uploaded_file($tmpname) && $type_1 == 'image' && $error == '0'){
						move_uploaded_file($tmpname,$newname);
					}
					
					
					//楼盘名字
					$data['x_name']=$_POST['x_name'];
					//楼盘图片
					$data['x_img'] = $picture;
					//楼盘位置
					$data['x_location']=$_POST['location'];
					//所 属  区
					$data['x_quyu']=$_POST['x_quyu'];
					//所属商圈
					$data['x_district']=$_POST['x_district'];
					//所属地铁线
					$data['x_subway']=$_POST['x_subway'];
					//所属地铁站
					$data['x_subway_station']=$_POST['x_subway_station'];
					//租赁方式
					$data['x_zulin']=$_POST['x_zulin'];
					//房源类型
					$data['x_type']=$_POST['x_type'];
					//房源位置
					$data['x_location']=$_POST['x_location'];
					//开发商
					$data['x_developers']=$_POST['x_developers'];
					//单价
					$data['x_sell']=$_POST['x_sell'];
					//总价
					$data['x_zongjia']=$_POST['x_zongjia'];
					//日租金
					$data['x_d_rent']=$_POST['x_d_rent'];
					//月租金
					$data['x_m_rent']=$_POST['x_m_rent'];
					//建筑面积
					$data['x_build_area']=$_POST['x_build_area'];
					//使用面积
					$data['x_use_area']=$_POST['x_use_area'];
					//详细标题
					$data['x_title']=$_POST['x_title'];
					//所在楼层
					$data['x_floor']=$_POST['x_floor'];
					//装修状况
					$data['x_decoration']=$_POST['x_decoration'];
					//楼盘等级
					$data['x_rating']=$_POST['x_rating'];
					//支付方式
					$data['x_pay_type']=$_POST['x_pay_type'];
					//配套设施
					$data['x_supproting']=$_POST['x_supproting'];
					//房源描述
					$data['x_description_info']=$_POST['x_description_info'];
					//图片描述
					$data['x_description_img']=$_POST['x_description_img'];
					//地图交通
					$data['x_description_map']=$_POST['x_description_map'];
					//楼盘简介
					$data['x_summary_info']=$_POST['x_summary_info'];
					//周边设施
					$data['x_nearby']=$_POST['x_nearby'];
					//所属经纪人
					$data['x_broker'] = $_POST['brokers'];
					//是否为精品房源
					$data['is_jingping'] = $_POST['radios'];
					$result = M("xiezilou")->data($data)->where("x_id = $x_id")->save();
					if($result){
						$this->assign("jumpUrl","__URL__/lists");
						$this->assign("waitSecond",3);
						$this->success("修改成功！！！");
					}else{
						$this->assign("jumpUrl","__URL__/lists");
						$this->assign("waitSecond",3);
						$this->error("修改失败！！！");					
					}
				}
			}
		
		}
		

	}